<?php

// 本类由系统自动生成，仅供测试用途
class SearchAction extends Action
{

    //查询成绩
    public function find()
    {
        //本年
        //date_default_timezone_set('Asia/Urumqi');
        $year=date('Y');
        for($i=0;$i<10;$i++){

            $yr[]=array(
                'l'=>$year-$i,
                'b'=>$year-$i+1
            );
        }
        $this->sch_year=$yr;


        import('Class.Category',APP_PATH);
        $cate=M('category')->order('sort ASC')->select();
        $this->cate=Category::unlimitedforlayer($cate);
        $this->you_qing_lian_jie_01=M('link')->order('id desc')->limit(0,12)->select();
        $this->you_qing_lian_jie_02=M('link')->order('id desc')->limit(12,12)->select();
        $this->ri_men=M('content')->order('count desc')->limit(13)->select();

        //$this->assign('na',$user);
        $this->display();

    }
    //显示成绩再次查询成绩
    public function show(){
        import('Class.Category',APP_PATH);
        $cate=M('category')->order('sort ASC')->select();
        $this->cate=Category::unlimitedforlayer($cate);
        $this->you_qing_lian_jie_01=M('link')->order('id desc')->limit(0,12)->select();
        $this->you_qing_lian_jie_02=M('link')->order('id desc')->limit(12,12)->select();
        $this->ri_men=M('content')->order('count desc')->limit(13)->select();
        $year=date('Y');
        for($i=0;$i<10;$i++){

            $yr[]=array(
                'l'=>$year-$i,
                'b'=>$year-$i+1
            );
        }
        $this->sch_year=$yr;

        //学年
        $school_year=$_POST['school_year'];

        //学期
        $term=$_POST['term'];

        //身份证号
        $this->number=$_POST['student_number'];

        //学籍号
        $student_number='L'.$_POST['student_number'];

        $user = M('student_info')->where(array('school_year' => $school_year,'term'=>$term,'student_number'=>$student_number))->select();
        //echo(count($user));
        for($i = 0; $i < count($user); $i++) {
            $ll[]=array(
                'subject'=>$user[$i]['subject'],
                'result'=>$user[$i]['result']
            );
        }

        //各科目名称和得分数
        $this->sub_res=$ll;

        $h=0;
        for($i = 0; $i < count($ll); $i++) {

            $rt+=$user[$i]['result'];
            if($user[$i]['result']>=60){
                $h++;
            }

        }

        //总分
        $this->z=$rt;

        //平均分
        $p=number_format($rt/count($ll),2);
        $this->p=$p;

        //合格科目数
        $this->hh=$h;

        $this->nati=$user[0];


        //按照全校信息
        $all_info = M('student_info')->where(array('school_year' => $school_year,'term'=>$term))->select();
        for($i = 0; $i < count($all_info); $i++) {
            if ($all_info[$i]['test_number'] != $all_info[$i - 1]['test_number']) {
                $all_test_num[] = array(
                    'test_number' => $all_info[$i]['test_number'],
                );
            }
        }

        //按照全校信息
        //全校平均分
        $ping=array();
        $student_info=M();
        for($i = 0; $i < count($all_test_num); $i++) {
            $i_t=$all_test_num[$i]['test_number'];
            $avv=$student_info->query("select avg(result) as a from sch_student_info where test_number=$i_t");
            $avv1=number_format($avv[0][a],2);
            array_push($ping,$avv1);
        }
        $ayu1=rsort($ping);


        //班级等级
        $cl=$user[0]['class'];
        $us = M('student_info')->where(array('class' => $cl))->select();
        //p($us);die;
        $all_z=array();
        $rr=0;
        for($i = 1; $i <= count($us); $i++) {

            $rr+=$us[$i-1]['result'];
            if($i % count($ll)==0 && $i!=0){
                array_push($all_z,$rr);
                $rr=0;
            }

        }
        $ayu=rsort($all_z);
        $d=array_search($rt,$all_z);
        $dd=array_search($p,$ping);
        $this->d=$d+1;
        $this->dd=$dd+1;
        $this->display('re_show');
        //$this->display('');
    }
}